package com.cloudsigns.factorymanager2.engineering.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.customview.DateViewDialog;
import com.cloudsigns.factorymanager2.project.customview.GeneralPurposePoupWindow;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

import java.util.Calendar;
import java.util.Locale;

public class EditEngineeringMaintenanceOrderDetailActivity extends BaseActivity implements ItemClickListener {

    private View rl_back;
    private TextView tv_title;
    private ImageView img_completion_date,img_maintenance_types_select;
    private EditText edt__completion_date,edt__maintenance_types;

    private GeneralPurposePoupWindow generalPurposePoupWindow;
    private String datas[] = {"电器故障", "质量问题","漏水问题","意外损坏"};

    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_edit_engineering_maintenance_detail);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        img_completion_date=findViewById(R.id.img_completion_date);
        img_maintenance_types_select=findViewById(R.id.img_maintenance_types_select);
        edt__completion_date=findViewById(R.id.edt__completion_date);
        edt__maintenance_types=findViewById(R.id.edt__maintenance_types);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText(getResources().getString(R.string.work_order_information));
    }

    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);
        img_completion_date.setOnClickListener(this);
        img_maintenance_types_select.setOnClickListener(this);
    }

    // 完成日期
    private void showDateDialog() {
        DateViewDialog endDateChooseDialog = new DateViewDialog(this,
                new DateViewDialog.DateChooseInterface() {
                    @Override
                    public void getDateTime(String time, boolean longTimeChecked) {
                        edt__completion_date.setText(time);
                    }
                });
        endDateChooseDialog.setTimePickerGone(true);

        Calendar dateAndTime = Calendar.getInstance(Locale.getDefault());
        endDateChooseDialog.setDateDialogTitle(dateAndTime.get(Calendar.YEAR) + "-" + (dateAndTime.get(Calendar.MONTH) + 1) + "-" + dateAndTime.get(Calendar.DAY_OF_MONTH));
        endDateChooseDialog.showDateChooseDialog();
    }

    /**
     * 维修种类窗口
     */
    private void showMaintanceTypesWindow(View anchor) {
        generalPurposePoupWindow = new GeneralPurposePoupWindow(this, datas);
        generalPurposePoupWindow.setItemClick(this);
        generalPurposePoupWindow.showPopupWindow(anchor);
    }

    @Override
    public void widgetClick(View v) {
        Intent mIntent;
        switch (v.getId()) {
            // 返回
            case R.id.rl_back:
                finish();
                break;
            // 完成日期
            case R.id.img_completion_date:
                showDateDialog();
                break;
            // 维修种类
            case R.id.img_maintenance_types_select:
                showMaintanceTypesWindow(edt__maintenance_types);
                break;
        }
    }

    @Override
    public void itemClick(View view, int position) {
        edt__maintenance_types.setText(datas[position]);
    }
}
